<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model as ThinkModel;
use think\model\concern\SoftDelete;
use think\Db;

/**
 *  用户收款信息 模型
**/
class UserPay extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'qt_user_viper_pay';
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;

    //开启软删除
//    use SoftDelete;
//    protected $defaultSoftDelete = 0;


    /**
     *  收款方式列表
    **/
    public function payList($uv_id)
    {
        $list = $this->where('uv_id',$uv_id)->select();
        return $list;
    }


    /**
     *  添加 / 编辑 支付地址
    **/
    public function setPay($uv_id,$data = [])
    {
        if (!$uv_id || empty($data))
        {
            return false;
        }
        $data['uv_id'] = $uv_id;


        if (!empty($data['id']))
        {
            $result = $this::update($data);
        }else{
            $result = $this::create($data);
        }

        if($result)
        {
            return true;
        }

        return false;
    }

    /**
     *  获取支付方式详情
     **/
    public function info($uv_id,$type)
    {
        $where = [];

        $where[] = ['uv_id','eq',$uv_id];
        $where[] = ['type','eq',$type];

        $info = $this->alias('ua')->where($where)->find();

        return $info;
    }


    /**
     *  删除
     **/
    public function del($uv_id,$id)
    {
        if (!$uv_id || !$id)
        {
            return false;
        }

        $result = $this->where(['id'=>$id,'uv_id'=>$uv_id])->delete();
        if($result)
        {
            return true;
        }else{
            return false;
        }

    }


}